<?php
  include_once 'config.php';
  include_once 'islogin.php';
  include_once 'fun.php';
  $_SESSION['isadmin']=isset($_SESSION['isadmin'])?$_SESSION['isadmin']:'';
    if ($_SESSION['isadmin']!=0&&$_SESSION['isadmin']!=-1) {
        header('Refresh:1;url=shop.php');
        die("请以销售身份登录");
    }
  $name = isset($_GET['Name'])?trim($_GET['Name']):'';
  $type = isset($_GET['type'])?trim($_GET['type']):'CONVERT(Name using GBK)';
  $order = isset($_GET['order'])?trim($_GET['order']):'ASC';

  if ($name) {
      $sql = "select * from product where Name like '%$name%' order by $type $order,CONVERT(Name using GBK) ASC ";
  } else {
      $sql = "select * from product order by $type $order ,CONVERT(Name USING GBK) ASC ";
  }

  $con=connect();
  $res = mysqli_query($con, $sql);

$filename="商品报表";
$time=1;
header("Content-type:application/vnd.ms-excel");  
header("Content-Disposition:filename=".$filename.".xls");  

$strexport="序号\t商品名称\t销售价格\t销量\t成本\t利润\r";  
while($ress=mysqli_fetch_row($res)){

    $strexport.=$time++."\t";
    $strexport.=$ress[1]."\t";
    $strexport.=$ress[2]."\t";
    $strexport.=$ress[5]."\t";
    $strexport.=$ress[6]."\t";
    $strexport.=$ress[7]-$ress[6]."\r";
   
   

}
$strexport=iconv('UTF-8',"GB2312",$strexport);  
exit($strexport);     
?>